;(function() {
		init_parsley();
		//同步会员信息
		$("#btn-sync").click(function(){
			var card_no=$("#card_no").val();
			var mobile=$("#mobile").val();
			if(card_no==null||(card_no.length<1)){
				toastr["error"]("卡号错误");
				return false;
			}else{
				loading();
				$.post(
					"/admin/member/get_member_info",
					{"card_no":card_no,"mobile":mobile},
					function(data){
						close_loading();
							 if(data.flag){
							  var result=data.data;
							 	$("#member_id").val(result.MemberID);
							 	$("#contract_id").val(result.ContractID);
							 	$("#mobile").val(result.Mobile);
							 	$("#name").val(result.MemberName);
							 	$("#start_date").val(result.StartDate);
							 	$("#end_date").val(result.EndDate);
							 	$("#contract_status").val(result.ContractStatus);
							 	$("#membership_type").val(result.MembershipType);
							 	$("#surplus_num").val(result.SurplusNum);
							 	toastr["success"]("成功");
							 }else{
							 	toastr["error"](data.msg,"错误提示");
							 }
					}
				);
				close_loading();
				 return false;
			}
		})
		
	   	$("#form-submit").click(function(){
	   		var flag=$('#validate-form').parsley('validate' );
	   		if(flag){
	   			var type=$("#membership_type").val();
	   			if(!(type==1||type==2||type==3||type==4)){
	   				toastr['error']("请先同步会员数据");
	   				return false;
	   			}
	   			loading();
	   			$.post(
	   				"/admin/member/sync",
	   				$("#validate-form").serialize(),
	   				function(data){
	   					close_loading();
			      		if(data.flag){
			      			$("#myModal").modal("hide");
			      			toastr['success']("操作成功！", ''); 
			      			$("#myform #btn-advanced-refresh").trigger("click");// 刷新页面
			      		}else{
			      		 	toastr['error'](data.msg,"操作失败！"); 
			      		}
	   				}
	   			);
	   		}
	   	})
	   	
})();
